package com.ht.medicaltreatment.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.bean.BloodsBean

class BloodFromRecordAdaptger:BaseQuickAdapter<BloodsBean,BaseViewHolder>(R.layout.item_parent_form_record_layout) {
    override fun convert(holder: BaseViewHolder, bean: BloodsBean) {
        val rootView = holder.getView<LinearLayout>(R.id.rootView)
        rootView.removeAllViews()
        bean.list.forEachIndexed{index, item ->
            val view = LayoutInflater.from(context).inflate(R.layout.item_form_record_layout,null,false)
            val line = view.findViewById<View>(R.id.line)
            if(index == 0){
                line.visibility = View.GONE
            }else{
                line.visibility = View.VISIBLE
            }
            view.findViewById<TextView>(R.id.tvPreTime).text = "前时间窗: ${item.preTimeStamp}min"
            view.findViewById<TextView>(R.id.tvAfterTimetvAfterTime).text = "后时间窗: ${item.afterTimeStamp}min"
            view.findViewById<TextView>(R.id.tvCaiXueR).text = "采血管容量：${item.capacity}"
            view.findViewById<TextView>(R.id.tvRealyCX).text = "实际采血量：${item.actualCapacity}"
            view.findViewById<TextView>(R.id.tvHYTime).text = "核验时间：${item.scanTime?:""}"
            view.findViewById<TextView>(R.id.tvRealCyTime).text = "实际采样时间：${item.actualTime?:""}"
            view.findViewById<TextView>(R.id.tvPlanTime).text = "计划采样时间：${item.expectTime?:""}"
            view.findViewById<TextView>(R.id.tvUserName).text = "操作者：${item.opertionPersonName?:""}"
            view.findViewById<TextView>(R.id.tvName).text = item.name
            view.findViewById<TextView>(R.id.tvRemark).text = "操作备注：${item.otherRemark?:""}"
            val imgStatus = view.findViewById<ImageView>(R.id.imgStatus)
            //0:未核验,1:核验正常 2:超窗 3:紧急跳过
            when(item.checkSuccess){
                0 -> imgStatus.setBackgroundResource(R.drawable.icon_why)
                1 -> imgStatus.setBackgroundResource(R.drawable.icon_cyzc)
                2 -> imgStatus.setBackgroundResource(R.drawable.icon_cycc)
                3 -> imgStatus.setBackgroundResource(R.drawable.icon_jjtg_form)
            }
            rootView.addView(view)
        }
    }

}
